package com.metacube.questionbank.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;

import com.metacube.questionbank.dto.QuestionDTO;

public class QuestionExtractor implements ResultSetExtractor<QuestionDTO> {

	QuestionDTO qDTO = new QuestionDTO();

	public QuestionDTO extractData(ResultSet res) throws SQLException,
			DataAccessException {

		try {
			qDTO.setqId(res.getInt(1));
			qDTO.setqTitle(res.getString(3));
			qDTO.setqBody(res.getString(4));
			qDTO.setModifiedDate(res.getDate(7));
			qDTO.setqAskedDate(res.getDate(2));
			qDTO.setUserId(res.getInt(5));
			qDTO.setIsActive(res.getInt(6));
			qDTO.setIsClose(res.getInt(8));
			qDTO.setVoteLike(res.getInt(9));
			qDTO.setVoteUnlike(res.getInt(10));
			qDTO.setPostedBy(res.getString(11));

		} catch (SQLException e) {

			System.out.println("Error While Set question data to list"
					+ e.getMessage());
		}
		return qDTO;
	}

	public QuestionDTO extractDataForQuestion(ResultSet res) throws SQLException,
			DataAccessException {

		try {
			qDTO.setqId(res.getInt(1));
			qDTO.setqTitle(res.getString(3));
			qDTO.setqBody(res.getString(4));
			qDTO.setModifiedDate(res.getDate(7));
			qDTO.setqAskedDate(res.getDate(2));
			qDTO.setUserId(res.getInt(5));
			qDTO.setIsActive(res.getInt(6));
			qDTO.setIsClose(res.getInt(8));
			qDTO.setVoteLike(res.getInt(9));
			qDTO.setVoteUnlike(res.getInt(10));

		} catch (SQLException e) {

			System.out.println("Error While Set question data to list"
					+ e.getMessage());
		}
		return qDTO;
	}

}
